#
# 农业舆情信息获取入口
#

import CngoldPriceCapturer
import CnHnbPriceCapturer
import CapturerDb
import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

## 金投网需要爬的数据配置
CngoldPriceCapturerList = [
    ('JO_111863', '水稻', '元/斤'),
    ('JO_111848', '玉米', '元/斤'),
    ('JO_111853', '大豆', '元/斤'),
    ('JO_111849', '小麦', '元/公斤'),
    ('JO_111838', '菜油', '元/斤'),
    ('JO_111802', '生猪', '元/斤')
]
## 惠农网需要爬的数据配置
CnHnbPriceCapturerList = [
    ('2002072', '水稻'),
    ('2002035', '玉米'),
    ('2002027', '大豆'),
    ('2002037', '小麦'),
    ('2002051-12696', '油菜籽'),
    ('2001186', '生猪')
]

def getSavePriceDate():

    # 价格信息列表
    price_info_list = []

    ## 金投网 ============================================================
    for e in CngoldPriceCapturerList:
        CngoldPriceCapturer.getPrices(e[0], e[1], e[2], price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111863', '水稻', '元/斤', price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111848', '玉米', '元/斤', price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111853', '大豆', '元/斤', price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111849', '小麦', '元/公斤', price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111838', '菜油', '元/斤', price_info_list)
        # CngoldPriceCapturer.getPrices('JO_111802', '生猪', '元/斤', price_info_list)

    ## 惠农网 ============================================================
    for e in CnHnbPriceCapturerList:
        CnHnbPriceCapturer.getPrices(e[0], e[1], price_info_list)
        # CnHnbPriceCapturer.getPrices('2002072', '水稻', price_info_list)
        # CnHnbPriceCapturer.getPrices('2002035', '玉米', price_info_list)
        # CnHnbPriceCapturer.getPrices('2002027', '大豆', price_info_list)
        # CnHnbPriceCapturer.getPrices('2002037', '小麦', price_info_list)
        # CnHnbPriceCapturer.getPrices('2002051-12696', '油菜籽', price_info_list)
        # CnHnbPriceCapturer.getPrices('2001186', '生猪', price_info_list)

    #入库
    if price_info_list:
        CapturerDb.savePriceBatch(price_info_list)

getSavePriceDate()
